from page.user_page import UserPage, get_driver
import unittest

class ShippingAddressTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 登录
        driver = get_driver()
        cls.userpage = UserPage(driver)
        cls.userpage.get(UserPage.userpage_url)
        cls.userpage.login_user()
        # 点击用户中心
        cls.userpage.user_center_click()
        # 点击收货地址
        cls.userpage.shipping_address_click()


    def test_01_add(self):
        # 新增
        self.userpage.distribution_area_select()
        self.userpage.name_input('test01')
        self.userpage.email_input('123@qq.com')
        self.userpage.address_input('花果山水帘洞')
        self.userpage.phone_input('18728977375')
        self.userpage.add_btn_click()

        # 断言
        assert_text = self.userpage.assert_text()
        self.assertEqual('您的收货地址信息已成功更新！',assert_text)

    def test_02_query(self):
        # 查询详细地址
        address_value = self.userpage.address_value()
        # 断言
        self.assertEqual('花果山水帘洞',address_value)

    def test_03_change(self):
        # 修改详细地址
        self.userpage.del_content()
        self.userpage.address_input('火焰山')
        self.userpage.change_btn_click()
        # 断言
        address_value = self.userpage.address_value()  # 修改后表单中详细地址的文本
        self.assertEqual('火焰山',address_value)

    def test_04_del(self):
        self.userpage.del_btn_click()
        # 断言
        address_value = self.userpage.address_value()  # 删除后表单中详细地址的文本
        self.assertNotEqual('火焰山',address_value)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.userpage.page_quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)



